-- -- Copyright 2014 Alessandro Gerlinger Romero -- -- This file is part of Hybrid fUML. -- -- Hybrid fUML is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- -- Hybrid fUML is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with Hybrid fUML. If not, see . -- ------------------------------------------------------------------------------------------------------------------------------------------------------------ -- APPROACH -- Agents are Value(ActivityExecution) for classifier behavior or for other activities -- Agents has a mode and a parent -- a supporting function for causality analysis is defined ------------------------------------------------------------------------------------------------------------------------------------------------------------ -- CLASS AGENTS - FUML_Semantics_Classes_Kernel_Value ------------------------------------------------------------------------------------------------------------------------------------------------------------ -- AGENTS function_fUML_Agents :: Dynamic (FUML_Semantics_Classes_Kernel_Value -> (FUML_Semantics_Classes_Kernel_Value -> Rule ())) function_fUML_Agents = initAssocs "fUML_Agents" [] instance AsmTerm (FUML_Semantics_Classes_Kernel_Value -> Rule ()) where asmDefault = rule_fUML_AgentEmpty instance Eq (FUML_Semantics_Classes_Kernel_Value -> Rule ()) where (==) = primAsmEq -- used to indicate that an agent is not more active -- removing from domain rule_fUML_AgentEmpty :: FUML_Semantics_Classes_Kernel_Value -> Rule () rule_fUML_AgentEmpty v = skip ------------------------------------------------------------------------------------------------------------------------------------------------------------ -- MODE FUNCTION FOR AGENTS ---------------------------------------- -- MEANING OF STATUSES ---------------------------------------- -- FUML_Status_Running - agent is running -- FUML_Status_Paused - agent will run only in the next reaction (paused on a control node) -- FUML_Status_WaitingExecution - agent is waiting a run from a child agent -- FUML_Status_WaitingSignal - agent is waiting a signal in the current discrete evaluation (this type of status is not allowed outside the iteration in the discrete steps) -- FUML_Status_WaitingSignalTempBlocked - agent will run in the next discrete evaluation (this type of status is not allowed outside the reaction) -- FUML_Status_WaitingSignalBlocked - agent will run in the next reaction due to the lack of the expected signal -- FUML_Status_WaitingEdgeValue - agent will waiting until a edge in the continuous part -- FUML_Status_NotInitialized - agent must run after initialization -- FUML_Status_Undef - agent is dead data FUML_Status = FUML_Status_Running | FUML_Status_Paused | FUML_Status_WaitingExecution | FUML_Status_WaitingSignal | FUML_Status_WaitingSignalTempBlocked | FUML_Status_WaitingSignalBlocked | FUML_Status_WaitingEdgeValue | FUML_Status_NotInitialized | FUML_Status_Undef instance AsmTerm FUML_Status where asmDefault = FUML_Status_Undef instance Ord FUML_Status where (<=) a b = ((findPos list a) < (findPos list b) || a == b) where list :: [FUML_Status] list = [FUML_Status_Running,FUML_Status_Paused,FUML_Status_WaitingExecution,FUML_Status_WaitingSignal,FUML_Status_WaitingSignalTempBlocked,FUML_Status_WaitingSignalBlocked,FUML_Status_WaitingEdgeValue,FUML_Status_NotInitialized,FUML_Status_Undef] findPos :: [FUML_Status] -> FUML_Status -> Int findPos list elem | head list == elem = 0 | otherwise = 1 + (findPos (tail list) elem) function_fUML_Agents_mode:: Dynamic (FUML_Semantics_Classes_Kernel_Value -> FUML_Status) function_fUML_Agents_mode = initAssocs "function_fUML_Agents_mode" [] ------------------------------------------------------------------------------------------------------------------------------------------------------------ -- PARENT FUNCTION FOR AGENTS function_fUML_Agents_parent :: Dynamic (FUML_Semantics_Classes_Kernel_Value -> FUML_Semantics_Classes_Kernel_Value) function_fUML_Agents_parent = initAssocs "function_fUML_Agents_parent" [] ------------------------------------------------------------------------------------------------------------------------------------------------------------ -- SUPPORT CAUSALITY ANALYSIS -- -- It stores the last snapshot for all running agents in the current discrete step iteration -- if it is the same for the same logical clock a causal problem exists -- -- Agent Reaction List of Other agents , Node running function_fUML_Agents_causalAnalysis :: Dynamic (FUML_Semantics_Classes_Kernel_Value -> (Int, [ (FUML_Semantics_Classes_Kernel_Value, FUML_Syntax_Activities_IntermediateActivities_ActivityNode)])) function_fUML_Agents_causalAnalysis = initAssocs "function_fUML_Agents_parent" [] instance AsmTerm (FUML_Semantics_Classes_Kernel_Value, FUML_Syntax_Activities_IntermediateActivities_ActivityNode) where asmDefault = (FUML_Semantics_Classes_Kernel_ValueEmpty, FUML_Syntax_Activities_IntermediateActivities_ActivityNodeEmpty) instance Eq (FUML_Semantics_Classes_Kernel_Value, FUML_Syntax_Activities_IntermediateActivities_ActivityNode) where (==) (v1,c) (bv1,bc) = v1 == bv1 && c == bc instance AsmTerm (Int, [ (FUML_Semantics_Classes_Kernel_Value, FUML_Syntax_Activities_IntermediateActivities_ActivityNode)]) where asmDefault = (0, [(FUML_Semantics_Classes_Kernel_ValueEmpty, FUML_Syntax_Activities_IntermediateActivities_ActivityNodeEmpty)]) instance Eq (Int, [ (FUML_Semantics_Classes_Kernel_Value, FUML_Syntax_Activities_IntermediateActivities_ActivityNode)]) where (==) (v1,c) (bv1,bc) = v1 == bv1 && c == bc ------------------------------------------------------------------------------------------------------------------------------------------------------------ -- HELPER FUNCTIONS function_fUML_Agents_childs :: FUML_Semantics_Classes_Kernel_Value -> {FUML_Semantics_Classes_Kernel_Value} function_fUML_Agents_childs v = mkSet ( filter (\vp -> (function_fUML_Agents_parent vp) == v) (expr2list $ dom $ function_fUML_Agents_parent)) function_fUML_Agents_childs_notInitialized :: FUML_Semantics_Classes_Kernel_Value -> {FUML_Semantics_Classes_Kernel_Value} function_fUML_Agents_childs_notInitialized v = mkSet ( filter (\vc -> function_fUML_Agents_mode(vc) == FUML_Status_NotInitialized) (expr2list $ function_fUML_Agents_childs v)) function_fUML_Agents_childs_terminated :: FUML_Semantics_Classes_Kernel_Value -> {FUML_Semantics_Classes_Kernel_Value} function_fUML_Agents_childs_terminated v = mkSet ( filter (\vc -> function_fUML_Agents_mode(vc) == FUML_Status_Undef) (expr2list $ function_fUML_Agents_childs v)) -- -- this function is used to check if some agent can change the status of the signals -- terminated, paused and blocked by absence of mandatory signals are not in this group function_fUML_Agents_runnableInThisDiscreteEvaluation :: {FUML_Semantics_Classes_Kernel_Value} function_fUML_Agents_runnableInThisDiscreteEvaluation = mkSet ( filter (\vp -> (function_fUML_Agents_mode vp) /= FUML_Status_Undef && (function_fUML_Agents_mode vp) /= FUML_Status_Paused && (function_fUML_Agents_mode vp) /= FUML_Status_WaitingSignalBlocked && (function_fUML_Agents_mode vp) /= FUML_Status_WaitingEdgeValue && (function_fUML_Agents_mode vp) /= FUML_Status_WaitingSignalTempBlocked ) (expr2list $ dom $ function_fUML_Agents)) -- -- used to check if it has agents waiting edge function_fUML_Agents_hasRunnableWaitingEdge :: Bool function_fUML_Agents_hasRunnableWaitingEdge = length (filter (\vp -> (function_fUML_Agents_mode vp) == FUML_Status_WaitingEdgeValue ) (expr2list $ dom $ function_fUML_Agents)) > 0 -- -- used to check if it has agents waiting edge function_fUML_Agents_hasRunnableWaitingSignalTempBlocked :: Bool function_fUML_Agents_hasRunnableWaitingSignalTempBlocked = length (filter (\vp -> (function_fUML_Agents_mode vp) == FUML_Status_WaitingSignalTempBlocked) (expr2list $ dom $ function_fUML_Agents)) > 0